<?php

namespace Database\Seeders;

use Carbon\Carbon;
use Flynsarmy\CsvSeeder\CsvSeeder;
use Illuminate\Support\Facades\DB;

class RegionSeeder extends CsvSeeder
{
  public function __construct()
  {
    $this->table = 'regions';
    $this->filename = base_path() . '/database/seeders/csvs/italian-regions.csv';
    $this->offset_rows = 1;
    $this->mapping = [
      2 => 'country_id',
      1 => 'name',
    ];
    $this->should_trim = true;
  }

  public function run()
  {
    parent::run();
    // this.timestamps, this.created_at, this.updated_at are not working
    // Quick fix: not to use them and update db colums after csv import
    DB::table('regions')->update([
      'created_at' => Carbon::now()->toString(),
      'updated_at' => Carbon::now()->toString(),
    ]);
  }
}
